//
//  GetPayInfoRequest.m
//  fashionbuyer
//
//  Created by ale tan on 2018/1/17.
//  Copyright © 2018年 ale tan. All rights reserved.
//

#import "GetPayInfoRequest.h"

@implementation GetPayInfoRequest

- (id)init{
    self = [super init];
    if (self) {
        self.aliPayUrl = @"payment/v1/alipay/app/pay";
        self.wechatUrl = @"payment/v1/wechat/app/pay";
    }
    return self;
}


- (void)getSignWithOrderNo:(NSString *)orderNo PayMethod:(FBPayTypeModel *)payMethod Complete:(RequestResult)requestResult{
    
    self.requestCallBack = requestResult;
    
    NSString *url = @"";
    //支付宝
    if ([payMethod.payMethodId integerValue] == 1||[payMethod.payMethodId integerValue] == 4) {
        url = self.aliPayUrl;
    }
    //微信
    else if ([payMethod.payMethodId integerValue] == 2){
        url = self.wechatUrl;
    }
    //其他
    else{
        NSLog(@"其他支付方式");
        return;
    }
    
    //支付id
    [self.parameters setObject:payMethod.payMethodId forKey:@"payMethodId"];
    
    //订单号
    if (orderNo) {
        [self.parameters setObject:orderNo forKey:@"orderNo"];
    }
    
    [ServiceManager postTrans:url withRequest:self.parameters success:^(NSDictionary *dictResponse, BOOL result) {
        
        if (result) {
            self.requestCallBack(dictResponse[@"data"], YES);
        }
        else{
            [FFTipsView showTips:dictResponse[@"toast"]];
            self.requestCallBack(dictResponse,NO);
        }
        
    } failure:^(NSError *error) {
        [FFTipsView showTips:@"网络连接失败"];
        self.requestCallBack(nil,NO);
    }];
}

@end
